using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace Haidou.Wpf.Util.Converters;

public class SourceToSize : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		string? param = parameter as string;

		return value is not BitmapImage image || string.IsNullOrEmpty(param) ? value : param.Equals("width") ? image.Width : image.Height;
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		return value;
	}
}